let target = [1, 2, 3, 4, 5, 6, 7, 8, 9];
let length = target.length;

// 1.
let nums = target.slice();
for (let i = 0; i < length; i++){
    let nowLength = nums.length;
    let idx = Math.floor(Math.random() * nowLength);
    target[i] = nums[idx];
    nums.splice(idx, 1);
}
console.log(target);

// 2. good
target = [1, 2, 3, 4, 5, 6, 7, 8, 9];
for (let i = length - 1; i > 0; i--){
    let idx = Math.floor(Math.random() * (i + 1));
    let temp = target[i];
    target[i] = target[idx];
    target[idx] = temp;
}
console.log(target);